import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'dart:math';

class PhotoHero extends StatelessWidget {
  final String photo;
  final VoidCallback onTap;
  final double width;

  const PhotoHero({Key key, this.photo, this.onTap, this.width})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      child: Hero(
        tag: photo,
        child: InkWell(
          onTap: onTap,
          child: Image.asset(
            photo,
            fit: BoxFit.contain,
          ),
        ),
      ),
    );
  }
}

class HeroAnimation extends StatelessWidget {
  @override
  Widget build(Object context) {
    timeDilation = 2.0;

    return Scaffold(
      appBar: AppBar(title: Text('肖像')),
      body: Center(
        child: PhotoHero(
            photo: 'images/1.PNG',
            width: 300,
            onTap: () {
              Navigator.of(context)
                  .push(MaterialPageRoute(builder: (BuildContext contex) {
                return Scaffold(
                  appBar: AppBar(
                    title: Text('zoom-im'),
                  ),
                  body: Container(
                    color: Colors.lightBlueAccent,
                    padding: EdgeInsets.all(16),
                    child: PhotoHero(
                      photo: 'images/1.PNG',
                      width: 50,
                      onTap: () {
                        Navigator.of(context).pop();
                      },
                    ),
                  ),
                );
              }));
            }),
      ),
    );
  }
}
